#!/bin/bash
set -ex
DT="jtpx_cs"
REMOTEDIR=/ZSTP/jtpx_data
DATADIR=/home/work/changsha_project/jtpx_data

if [ ! -e ${DATADIR}/${DT}.tgz ]; then
    echo "data not ready"
    exit 0;
fi

cd ${DATADIR}

expect <<EOF
set timeout -1

spawn sftp haizhisftp@zstp.ibcs.cn
expect "password:"
send "Zstp@36:bcs\r"

expect "sftp>"
send "mkdir ${REMOTEDIR}\r"

expect "sftp>"
send "put ${DATADIR}/${DT}.tgz ${REMOTEDIR}\r"

expect "sftp>"
send "quit\r"
expect eof
EOF

 echo "完成数据传输没有异常退出.."
